package com.demo.inject.factory;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestMyBeanFactory {
    //自定义工厂
    @Test
    public void test1(){
        //1.创建工厂
        MyBeanFactory myBeanFactory=new MyBeanFactory();
        //2.通过工厂实例，获得对象
        UserService userService= myBeanFactory.createService();
        userService.addUser();
    }
    
    //spring工厂
    @Test
    public void test2(){
        String xmlPath="inject/factory/beans.xml";
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext(xmlPath);
        UserService userService=applicationContext.getBean("userService",UserService.class);
        userService.addUser();
    }
}
